﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;

using DM_Article.Model;

namespace DM_Article.Bll
{
    public class bigclassbll
    {
        public static int add(OleDbConnection conn, bigclass model)
        {
            OleDbCommand odc = new OleDbCommand();
            odc.CommandText = "insert into bigclass(bigclassname)values('" + model.bigclassname + "')";
            odc.Connection = conn;
            return odc.ExecuteNonQuery();
        }

        public static int update(OleDbConnection conn, bigclass model)
        {
            OleDbCommand odc = new OleDbCommand();
            odc.CommandText = "update bigclass set bigclassname ='" + model.bigclassname + "' where bigclassid=" + model.bigclassid;
            odc.Connection = conn;
            return odc.ExecuteNonQuery();
        }

        public static int delete(OleDbConnection conn, string bigclassid)
        {
            OleDbCommand odc = new OleDbCommand();
            odc.CommandText = "delete from bigclass where bigclassid=" + bigclassid;
            odc.Connection = conn;
            return odc.ExecuteNonQuery();
        }


        public static bigclass getBigclassDetail(OleDbConnection conn, string bigclassid)
        {
            OleDbDataAdapter odda = new OleDbDataAdapter("SELECT [USERID],[USERNAME] FROM ADMIN", conn);
            odda.SelectCommand = new OleDbCommand();
            odda.SelectCommand.CommandText = "select [bigclassid],[bigclassname] from bigclass where bigclassid=" + bigclassid;
            odda.SelectCommand.Connection = conn;
            DataTable dt = new DataTable();
            odda.Fill(dt);

            bigclass model = new bigclass();
            if (dt != null && dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["bigclassname"].ToString() != "")
                {
                    model.bigclassname = dt.Rows[0]["bigclassname"].ToString();
                }
                return model;
            }
            else
            {
                return null;
            }

        }

        public static DataTable getBigclassTable(OleDbConnection conn)
        {
            OleDbDataAdapter odda = new OleDbDataAdapter();
            odda.SelectCommand = new OleDbCommand();
            odda.SelectCommand.CommandText = "select [bigclassid],[bigclassname] from bigclass";
            odda.SelectCommand.Connection = conn;
            DataTable dt = new DataTable();
            odda.Fill(dt);
            return dt;
        }

        public static int getBigClassIdbyName(OleDbConnection conn, string name)
        {
            OleDbDataAdapter odda = new OleDbDataAdapter();
            odda.SelectCommand = new OleDbCommand();
            odda.SelectCommand.CommandText = "select [bigclassid] from bigclass where bigclassname='" + name + "'";
            odda.SelectCommand.Connection = conn;
            DataTable dt = new DataTable();
            odda.Fill(dt);

            if (dt != null && dt.Rows.Count > 0)
            {
                if (dt.Rows[0]["bigclassid"].ToString() != "")
                {
                    return Convert.ToInt32(dt.Rows[0]["bigclassid"].ToString());
                }
            }

            return 0;
        }
    }
}
